using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Configuration;

namespace UserRegisterService.DataAccess
{
    class UserRegister
    {
        internal static int Register(UserRegisterService.Contract.User customer)
        {
            string connString = ConfigurationManager.AppSettings["MycomicsConnectionstring"];
            SqlConnection conn = new SqlConnection(connString);
            try
            {
                conn.Open();
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = conn;
                cmd.CommandText = "insert into customer values(@firstname, @lastname)";
                cmd.Parameters.Add(new SqlParameter("@firstname", customer.FirstName));
                cmd.Parameters.Add(new SqlParameter("@lastname", customer.LastName));
                cmd.ExecuteNonQuery();

                return (int)new SqlCommand("select count(*) from customer", conn).ExecuteScalar();
            }
            finally
            {
                conn.Close();
            }
        }
    }
}
